package com.bootdo.app.exception;

import com.bootdo.app.utils.returnresponse.ServerResponse;
import com.mysql.fabric.Server;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 【@author 】 @fan
 * 【@Email  】 mooncluyed@outlook.com
 * 【类解释  】
 * 【@Date   】 2018/5/14 0014
 **/
@ControllerAdvice
public class AppAjaxException {
    private final static Logger logger = LoggerFactory.getLogger(AppAjaxException.class);

    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public ServerResponse<String> myHandle (Exception e) {
        if (e instanceof AppException) {
            AppException girlException = (AppException)e;
            return ServerResponse.createByErrorCodeMessage(girlException.getCode() , e.getMessage());
        }else{
            logger.error("【系统异常】",e);
            return ServerResponse.createByErrorMessage("未知错误,请联系管理员");
        }
    }

}
